<!--
 * @Author: Vi卡农
 * @Date: 2020-03-18 18:30:03
 * @LastEditTime: 2020-05-22 16:28:03
 * @Description: -统计中心-
 * @FilePath: \cshf_admin\src\views\modules\statistic\statistic.vue
 -->
<template>
  <el-card shadow="never" class="aui-card--fill" ref="fromc">
    <div class="mod-statistic__statistic}">
      <el-form :inline="true" :model="dataForm" @keyup.enter.native="getDataList()" ref="froma">
        <el-form-item>
          类型：
          <el-select v-model="dataForm.type" class="FormSelect" clearable>
            <el-option label="个人" value="1"></el-option>
            <el-option label="组" value="2"></el-option>
            <el-option label="门店" value="3"></el-option>
            <el-option label="区域" value="4"></el-option>
            <el-option label="部门" value="5"></el-option>
            <el-option label="公司" value="6"></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          时间：
          <el-select
            v-model="dataForm.date"
            @change="dateSelectChange"
            class="FormSelect"
            clearable
          >
            <el-option label="自定义" value="6"></el-option>
            <el-option label="当天" value="1"></el-option>
            <el-option label="本周" value="2"></el-option>
            <el-option label="本月" value="3"></el-option>
            <el-option label="本季度" value="4"></el-option>
            <el-option label="今年" value="5"></el-option>
          </el-select>&nbsp;
          <el-date-picker
            v-model="dataForm.createDates"
            type="date"
            placeholder="开始时间"
            value-format="yyyy-MM-dd"
            style="width:136px"
            :disabled="dataForm.date!='6'"
          ></el-date-picker>
          {{' -'}}
          <el-date-picker
            v-model="dataForm.createDatee"
            type="date"
            placeholder="结束时间"
            value-format="yyyy-MM-dd"
            style="width:136px"
            :disabled="dataForm.date!='6'"
          ></el-date-picker>
        </el-form-item>
        <el-form-item>
          部门：
          <el-cascader
            class="FormSelect"
            v-model="deptSelectVal"
            :options="this.$store.state.DeptList"
            :show-all-levels="false"
            @change="deptIdChange"
            :props="deptProps"
            ref="myCascader"
            clearable
          ></el-cascader>
        </el-form-item>
        <el-form-item>
          人员：
          <el-select v-model="dataForm.userId" placeholder="请选择" class="FormSelect" clearable>
            <el-option
              v-for="item in maintainList"
              :key="item.id"
              :label="item.realName"
              :value="item.id"
            ></el-option>
          </el-select>
        </el-form-item>
        <el-form-item>
          <el-button @click="getDataList()">{{ $t('query') }}</el-button>
        </el-form-item>
        <el-form-item>
          <el-button
            v-if="$hasPermission('statistic:statistic:export')"
            type="info"
            @click="exportHandle()"
          >{{ $t('export') }}</el-button>
        </el-form-item>
      </el-form>
      <el-table
        v-loading="dataListLoading"
        :data="dataList"
         :height="autoTabHeight"
         show-summary
        border
        @selection-change="dataListSelectionChangeHandle"
        style="width: 100%;"
      >
        <!-- <el-table-column type="selection" header-align="center" align="center" width="50"></el-table-column>
        <el-table-column prop="id" label="id" header-align="center" align="center"></el-table-column>-->
        <!--<el-table-column prop="type" label="统计类型" header-align="center" align="center"></el-table-column>-->
        <el-table-column prop="name" label="对象名" header-align="center" align="center"></el-table-column>
        <el-table-column prop="houseNum" label="房源统计" header-align="center" align="center">
          <template slot-scope="scope">
            <el-button type="text" @click="goList_FY(scope.row)">{{(scope.row.houseNum)}}</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="houseKeyNum" label="房源钥匙统计" header-align="center" align="center">
          <template slot-scope="scope">
            <el-button type="text" @click="goList_FYKey(scope.row)">{{(scope.row.houseKeyNum)}}</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="houseImageNum" label="房源实勘统计" header-align="center" align="center">
          <template slot-scope="scope">
            <el-button type="text" @click="goList_FYImage(scope.row)">{{(scope.row.houseImageNum)}}</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="houseSpareNum" label="房源备件统计" header-align="center" align="center">
          <template slot-scope="scope">
            <el-button type="text" @click="goList_FYSpare(scope.row)">{{(scope.row.houseSpareNum)}}</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="houseFollowNum" label="房源跟进统计" header-align="center" align="center">
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="goList_FYfollow(scope.row)"
            >{{(scope.row.houseFollowNum)}}</el-button>
          </template>
        </el-table-column>
        <el-table-column prop="customerNum" label="客源统计" header-align="center" align="center">
          <template slot-scope="scope">
            <el-button type="text" @click="goList_KY(scope.row)">{{(scope.row.customerNum)}}</el-button>
          </template>
        </el-table-column>
        <el-table-column
          prop="customerFollowNum"
          label="客源跟进统计"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="goList_KYfollow(scope.row)"
            >{{(scope.row.customerFollowNum)}}</el-button>
          </template>
        </el-table-column>
        <el-table-column
          prop="customerLeaseVisit"
          label="租赁带看统计"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="goList_KYLeaseVisit(scope.row)"
            >{{(scope.row.customerLeaseVisit)}}</el-button>
          </template>
        </el-table-column>
        <el-table-column
          prop="customerSelllVisit"
          label="买卖带看统计"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="goList_KYSelllVisit(scope.row)"
            >{{(scope.row.customerSelllVisit)}}</el-button>
          </template>
        </el-table-column>
        <el-table-column
          prop="houseReFollowNum"
          label="商机房跟进"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="goList_KYSelllVisit(scope.row)"
            >{{(scope.row.houseReFollowNum)}}</el-button>
          </template>
        </el-table-column>
         <el-table-column
          prop="customerReFollowNum"
          label="商机客跟进"
          header-align="center"
          align="center"
        >
          <template slot-scope="scope">
            <el-button
              type="text"
              @click="goList_KYSelllVisit(scope.row)"
            >{{(scope.row.customerReFollowNum)}}</el-button>
          </template>
        </el-table-column>
      </el-table>
      <div class="paginationBox">
        <el-pagination
          :current-page="page"
          :page-sizes="[10, 20, 50, 100]"
          :page-size="limit"
          :total="total"
          layout="total, sizes, prev, pager, next, jumper"
          @size-change="pageSizeChangeHandle"
          @current-change="pageCurrentChangeHandle"
        ></el-pagination>
      </div>
    </div>
  </el-card>
</template>

<script>
import mixinViewModule from "@/mixins/view-module";
export default {
  mixins: [mixinViewModule],
  data() {
    return {
      mixinViewModuleOptions: {
        getDataListURL: "/statistic/statistic/statisticList",
        getDataListIsPage: true,
        exportURL: "/statistic/statistic/export",
        deleteURL: "/statistic/statistic",
        deleteIsBatch: true,
      },
      dataForm: {
        id: "",
        type: "1",
        createDates: "",
        createDatee: "",
        date: "6",
        deptId: "",
        userId: "",
      },
      deptProps: {
        value: "id",
        label: "name",
        checkStrictly: true,
      },
      deptSelectVal: "",
      maintainList: this.$store.state.maintainList,
    };
  },
  components: {
    // AddOrUpdate
  },
  created() {
    if (this.$route.query.statisticType) {
      this.statisticOpen();
    } else {
      this.getDataList();
    }
    this.$nextTick(() => {
      this.autoWidth();
    });
  },
  mounted() {
    let _this = this;
    window.onresize = function () {
      _this.autoWidth();
    };
  },
  methods: {
     autoWidth() {
      let that = this;
      let formh = that.$refs.froma.$el.offsetHeight;
      let h = that.$refs.fromc.$el.offsetHeight;
      let heightStyle = h - formh - 45;
      that.autoTabHeight = heightStyle;
    },
    // 日期方式切换
    dateSelectChange(val) {
      if (val != "6") {
        this.dataForm.createDates = "";
        this.dataForm.createDatee = "";
      }
    },
    deptIdChange(val) {
      let a = "";
      if (this.$refs.myCascader.getCheckedNodes()[0]) {
        a = this.$refs.myCascader.getCheckedNodes()[0].value;
        this.dataForm.deptId = a;
        this.getUserList(a);
      } else {
        this.dataForm.deptId = "";
      }
    },
    // 获取部门员工列表
    getUserList(deptId) {
      let _this = this;
      this.$http
        .get(`/sys/user/deptUserList`, {
          params: {
            deptId: deptId,
          },
        })
        .then(({ data: res }) => {
          if (res.code !== 0) {
            return this.$message.error(res.msg);
          }
          _this.maintainList = res.data;
        })
        .catch(() => {});
    },
    //跳转到房源列表
    goList_FY(row) {
      this.$router.push({
        name: "house-houseinfo",
        query: {
          id: row.id,
          state: 1,
          resource: 1,
          statisticType: this.dataForm.type,
          houseModuleId: 1,
          date: this.dataForm.date,
          createDates: this.dataForm.createDates,
          createDatee: this.dataForm.createDatee,
        },
      });
    },
    //跳转到房源钥匙列表
    goList_FYKey(row) {
      this.$router.push({
        name: "house-page-housekey",
        query: {
          userId: row.id,
        },
      });
    },
    //跳转到实勘列表
    goList_FYImage(row) {
      this.$router.push({
        name: "house-houseinfo",
        query: {
          id: row.id,
          state: "",
          statisticType: this.dataForm.type,
          houseModuleId: 2,
          resource: 1,
          date: this.dataForm.date,
          createDates: this.dataForm.createDates,
          createDatee: this.dataForm.createDatee,
        },
      });
    },
    //跳转到备件列表
    goList_FYSpare(row) {
      this.$router.push({
        name: "house-houseinfo",
        query: {
          id: row.id,
          state: "",
          statisticType: this.dataForm.type,
          houseModuleId: 4,
          resource: 1,
          date: this.dataForm.date,
          createDates: this.dataForm.createDates,
          createDatee: this.dataForm.createDatee,
        },
      });
    },
    //跳转到房源跟进列表
    goList_FYfollow(row) {
      this.$router.push({
        name: "house-housefollow",
        query: {
          id: row.id,
          statisticType: this.dataForm.type,
          houseModuleId: 3,
          deptId: this.dataForm.deptId,
          date: this.dataForm.date,
          createDates: this.dataForm.createDates,
          createDatee: this.dataForm.createDatee,
        },
      });
    },
    //跳转到客源列表
    goList_KY(row) {
      this.$router.push({
        name: "customer-customerhouseinfo",
        query: {
          id: row.id,
          statisticType: this.dataForm.type,
          state: 1,
          customerModuleId: 1,
          date: this.dataForm.date,
          createDates: this.dataForm.createDates,
          createDatee: this.dataForm.createDatee,
        },
      });
    },
    //跳转到客源跟进列表
    goList_KYfollow(row) {
      this.$router.push({
        name: "customer-page-customerfollow",
        query: {
          id: row.id,
          statisticType: this.dataForm.type,
          customerModuleId: 2,
          deptId: this.dataForm.deptId,
          date: this.dataForm.date,
          createDates: this.dataForm.createDates,
          createDatee: this.dataForm.createDatee,
        },
      });
    },
    //跳转到客源租赁带看列表
    goList_KYLeaseVisit(row) {
      this.$router.push({
        name: "customer-page-customervisit",
        query: {
          id: row.id,
          statisticType: this.dataForm.type,
          customerModuleId: 3,
          transactionType: 1,
          deptId: this.dataForm.deptId,
          date: this.dataForm.date,
          createDates: this.dataForm.createDates,
          createDatee: this.dataForm.createDatee,
        },
      });
    },
    //跳转到客源买卖带看列表
    goList_KYSelllVisit(row) {
      this.$router.push({
        name: "customer-page-customervisit",
        query: {
          id: row.id,
          statisticType: this.dataForm.type,
          customerModuleId: 3,
          transactionType: 0,
          deptId: this.dataForm.deptId,
          date: this.dataForm.date,
          createDates: this.dataForm.createDates,
          createDatee: this.dataForm.createDatee,
        },
      });
    },
  },

  watch: {
    dataForm: {
      handler(nowVal, oldVal) {
        this.getDataList();
      },
      deep: true,
    },
  },
};
</script>
